package com.honghu.cloud.utils;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.google.common.collect.Maps;
import com.honghu.cloud.utils.CommUtil;


/**
 * 商品查询语句工具类
 * @author Administrator
 *
 */
@Component
public class QueryTools {
	
	/**
	 * 
	 * @param currentPage
	 * @param orderBy
	 * @param orderType
	 * @return
	 */
	public Map<String, Object> getParams(String currentPage, String orderBy,
			String orderType) {
		int cp = CommUtil.null2Int(currentPage);

		Map<String, Object> params = Maps.newHashMap();
		// 这个src_currentPage需要返回到前台,让前台显示页码用的

		if (cp == 0) {
			cp = 1;
		}

		params.put("currentPage", cp);
		params.put("pageSize", 12);

		params.put("orderBy", orderBy);
		params.put("orderType", orderType);

		if (StringUtils.isBlank(orderBy) || StringUtils.isBlank(orderType)) {
			params.put("orderBy", "addTime");
			params.put("orderType", "asc");
		}

		return params;
	}

	/**
	 * 
	 * @param currentPage
	 * @param orderBy
	 * @param orderType
	 * @return
	 */
	public Map<String, Object> getParams(String currentPage, Integer pageSize,
			String orderBy, String orderType) {
		int cp = CommUtil.null2Int(currentPage);

		Map<String, Object> params = Maps.newHashMap();

		if (cp == 0) {
			cp = 1;
		}

		if (pageSize == null) {
			pageSize = 12;
		}

		params.put("currentPage", cp);
		params.put("pageSize", pageSize);

		params.put("orderBy", orderBy);
		params.put("orderType", orderType);

		if (StringUtils.isBlank(orderBy) || StringUtils.isBlank(orderType)) {
			params.put("orderBy", "addTime");
			params.put("orderType", "asc");
		}

		return params;
	}
	
}
